<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var merge = function (nums1, m, nums2, n) {
            let i = m - 1, j = n - 1, tail = m + n - 1, num;
            while (i >= 0 || j >= 0) {
                if (i === -1) {
                    num = nums2[j--]
                } else if (j === -1) {
                    num = nums1[i--]
                } else if (nums1[i] > nums2[j]) {
                    num = nums1[i--]
                } else {
                    num = nums2[j--]
                }
                nums1[tail--] = num
            }
            return nums1
        };
        console.log(merge([1, 2, 3, 0, 0, 0], 3, [2, 5, 6], 3));
    </script>
</body>

</html>